package cn.rubintry.bug.hunting.common.http.viewmodel

import androidx.activity.ComponentActivity
import androidx.lifecycle.MutableLiveData
import cn.rubintry.bug.hunting.common.http.api.WebApi
import cn.rubintry.bug.hunting.pojo.BaseModel
import cn.rubintry.bug.hunting.pojo.UserDataModel
import cn.rubintry.bug.hunting.pojo.VerifyCodeModel
import cn.rubintry.bug.lib.network.http.NetApiManager
import cn.rubintry.bug.lib.network.http.viewmodel.BaseViewModel

class LoginViewModel() : BaseViewModel() {

    val verifyData = MutableLiveData<BaseModel<VerifyCodeModel>>()
    val loginData = MutableLiveData<BaseModel<UserDataModel>>()

    fun getVerifyCode(){
        request<WebApi,BaseModel<VerifyCodeModel>>(
            NetApiManager.getInstance().getApi(WebApi::class.java),
            WebApi::getVerifyCode,
            { data ->
                data?.let {
                    verifyData.value = it
                }
            }
        )
    }

    fun login(userName: String , password: String , uuid: String , verifyCode: String){
        request<WebApi, BaseModel<UserDataModel>>(
            NetApiManager.getInstance().getApi(WebApi::class.java),
            WebApi::login,
            { data ->
                data?.let {
                    loginData.value = it
                }
            },userName , password , uuid , verifyCode
        )
    }
}